package com.cocoiko;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

import com.cocoiko.tools.facebook.FacebookLogin;
import com.cocoiko.tools.twitter.Constants;
import com.cocoiko.tools.twitter.RequestOAuthTwitter;
import com.cocoiko.tools.twitter.TwitterUtils;
import com.cocoiko.utils.CocoikoConstains;

public class Register extends Activity implements OnClickListener {

	Button back;
	ImageView twitter;
	ImageView facebook;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.register);

		//
		back = (Button) findViewById(R.id.back);
		back.setOnClickListener(this);

		twitter = (ImageView) findViewById(R.id.twitter);
		facebook = (ImageView) findViewById(R.id.facebook);

		twitter.setOnClickListener(this);
		facebook.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == back) {
			finish();
		}
		if (v == twitter) {
			SharedPreferences prefs = getSharedPreferences(
					CocoikoConstains.SHARE_PREFER_NAME, MODE_PRIVATE);
			if (!TwitterUtils.isAuthenticated(prefs)) {
				Intent intent = new Intent(Register.this,
						RequestOAuthTwitter.class);
				startActivity(intent);
				finish();
			} else {
				Intent intent = new Intent(this, Setting.class);
				intent.putExtra("TYPE", CocoikoConstains.REGISTER);
				intent.putExtra("ACCOUNT", CocoikoConstains.TWITTER);
				startActivity(intent);
				finish();
			}
		}
		if (v == facebook) {
			FacebookLogin fb = new FacebookLogin(this);
			if(!fb.isOAuth()){
				fb.facebookOAuth();
			}
			Intent intent = new Intent(this, Setting.class);
			intent.putExtra("TYPE", CocoikoConstains.REGISTER);
			intent.putExtra("ACCOUNT", CocoikoConstains.FACEBOOK);
			startActivity(intent);
			finish();
		}
	}
}
